global root_dir = "`1'"

include "$root_dir/code/config/config.do"

cap noi log using ${log_dir}/table_A1_industry_summary.log, replace name(tabl)

capture noi {
	* Summary statics for industry level variables


	global cvers _ipc4
	global indvers ind6090

	texdoc init ${tab_dir}/appendix/Table_A1_industry_summary.tex, replace
	texdoc stlog, nolog


	use ${final_dir}/${indvers}_patents_regression_data${cvers}.dta, clear

	foreach var in sh_auto95_use computeruse dqsts dqfing dratioHL d_lshare_nber  {
		su `var' [aw = emp_mid_alm], detail
		foreach stat in mean sd min p10 p50 p90 max { 
			sleep 1200
			texdoc local `stat'_`var' : display %9.3f r(`stat')
		}
		foreach stat in N {
			sleep 1200
			texdoc local `stat'_`var' : display %9.0f r(`stat')
		}
	}

	preserve
	keep if in_mk == 1
	foreach var in sh_auto95_mk  {
		su `var' [aw = emp_mid_alm], detail
		foreach stat in mean sd min p10 p50 p90 max { 
			sleep 1200
			texdoc local `stat'_`var' : display %9.3f r(`stat')
		}
		foreach stat in N { 
			sleep 1200
			texdoc local `stat'_`var' : display %9.0f r(`stat')
		}
	}
	restore

	use ${final_dir}/beaind_patents_regression_data${cvers}.dta, clear

	foreach var in d_lshare  {
		su `var' [aw = emp_mid_alm], detail
		foreach stat in mean sd min p10 p50 p90 max { 
			sleep 1200
			texdoc local `stat'_`var' : display %9.3f r(`stat')
		}
		foreach stat in N { 
			sleep 1200
			texdoc local `stat'_`var' : display %9.0f r(`stat')
		}
	}


	texdoc local notes "This table shows summary statistics for the variables in our industry level regression. Share automation (using industry) represents the share of automation patents among machinery patents used by an industry. Share automation (inventing industry) represents the share of automation patents among machinery patents invented by an industry. Patents are USPTO granted patents over the years 1980-1998. $\Delta$ Computer use is the change in computer per-employee between 1997 and 1984. $\Delta$ routine cognitive, routine manual and high/low skill workers denote changes in these variables between 1980-1998. $\Delta$ labor share (NBER manufacutring) is the change in payroll / value added in the NBER-CES manufacuring industry database. $\Delta$ Labor Share (BEA)  is the change in total compensation / value added in 60 aggregated industries. Industries are weighed by mean industry employment in 1980 and 1998."
	texdoc stlog close
	include ${code_dir}/config/texdoctools.do
	tex `texpreamble'

	/*tex
	\begin{tabular}{@{}l*{8}{c}@{}}
	\toprule

	& Mean & SD & Min & P10 & P50 & P90 & Max & N \\

	\midrule

	Share automation (using industry) & `mean_sh_auto95_use' & `sd_sh_auto95_use' & `min_sh_auto95_use' & `p10_sh_auto95_use' & `p50_sh_auto95_use' & `p90_sh_auto95_use' & `max_sh_auto95_use' & `N_sh_auto95_use' \\

	Share automation (inventing industry) & `mean_sh_auto95_mk' & `sd_sh_auto95_mk' & `min_sh_auto95_mk' & `p10_sh_auto95_mk' & `p50_sh_auto95_mk' & `p90_sh_auto95_mk' & `max_sh_auto95_mk' & `N_sh_auto95_mk' \\

	$\Delta$ Computer use (1984-1997) & `mean_computeruse' & `sd_computeruse' & `min_computeruse' & `p10_computeruse' & `p50_computeruse' & `p90_computeruse' & `max_computeruse' & `N_computeruse' \\

	$\Delta$ Routine cognitive & `mean_dqsts' & `sd_dqsts' & `min_dqsts' & `p10_dqsts' & `p50_dqsts' & `p90_dqsts' & `max_dqsts' & `N_dqsts' \\

	$\Delta$ Routine manual & `mean_dqfing' & `sd_dqfing' & `min_dqfing' & `p10_dqfing' & `p50_dqfing' & `p90_dqfing' & `max_dqfing' & `N_dqfing' \\

	$\Delta$ High/low skill workers & `mean_dratioHL' & `sd_dratioHL' & `min_dratioHL' & `p10_dratioHL' & `p50_dratioHL' & `p90_dratioHL' &`max_dratioHL' & `N_dratioHL' \\

	$\Delta$ Labor share (NBER manufacturing) & `mean_d_lshare_nber' & `sd_d_lshare_nber' & `min_d_lshare_nber' & `p10_d_lshare_nber' & `p50_d_lshare_nber' & `p90_d_lshare_nber' & `max_d_lshare_nber' & `N_d_lshare_nber' \\

	$\Delta$ Labor share (BEA) & `mean_d_lshare' & `sd_d_lshare' & `min_d_lshare' & `p10_d_lshare' & `p50_d_lshare' & `p90_d_lshare' & `max_d_lshare' & `N_d_lshare' \\


	\bottomrule
	\end{tabular}
	tex*/
	tex `texpostamble'
	texdoc close

}
if _rc == 0 {
    display "Execution finished successfully."
}
else {
    display "Execution finished with errors."
}

cap log close tabl

